<template>
    <div class="header">
        <el-image class="header_logo" :src="require('@/assets/yflogo-2.png')"></el-image>

        <div class="head_right">
            <div class="user_box">
                <span class="user_name">
                    <el-image class="user_icon" :src="require('@/assets/peple_icon.png')"></el-image>
                    {{ username }} {{ user_position }}
                </span>
                <span class="user_mobile">绑定专属号：{{ mobile }}</span>
            </div>
            <div class="icon_list">
                <span @click="refresh"><i class="el-icon-refresh-right"></i> 刷新</span>
            </div>
            <el-dropdown @command="handleCommand">
                <span class="el-dropdown-link">
                    <i class="el-icon-setting"></i> 设置
                </span>
                <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item command="首页">首页</el-dropdown-item>
                    <el-dropdown-item divided command="退出">退出</el-dropdown-item>
                </el-dropdown-menu>
            </el-dropdown>
        </div>
    </div>
</template>

<script>
export default {
    name: 'Header',
    data() {
        return {
            username: localStorage.username || '',
            user_position: '超级管理员',
            mobile: '13800138000'
        }
    },
    methods: {
        //刷新
        refresh() {
            this.$emit('refresh')
        },
        //下拉框点击
        handleCommand(item) {
            console.log(item)
            if(item == '首页'){
                sessionStorage.removeItem('nav_tabs')   //移除存储
                this.$router.push('/index')
            }
            else if(item == '退出'){
                this.$confirm('您确定要退出登录吗？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    localStorage.clear()
                    sessionStorage.clear()
                    this.$router.push('/login')
                }).catch(() => {
                    //取消   
                });
                
            }
        }
    }
}
</script>

<style lang="scss" scoped>
.header{
    height: 35px;
    background-color: #F7AB00;

    .header_logo{
        width: 84px;
        padding: 8px 0 0 50px;
    }

    .head_right{
        float: right;
        height: 35px;
        padding: 0 20px 0 0;

        .user_box{
            display: inline-block;
            font-size: 12px;
            padding-right: 10px;
            margin-right: 10px;
            border-right: 1px solid #000;

            .user_name{
                padding-right: 10px;

                .user_icon{
                    vertical-align: text-top;
                    width: 18px;
                }
            }
        }

        .icon_list{
            display: inline-block;
            font-size: 12px;
            height: 35px;
            line-height: 35px;

            span{
                padding: 0 5px;
                display: block;
                height: 35px;
                transition: all .2s;
                cursor: pointer;
            }
        }

        .el-dropdown{
            font-size: 12px;
            color: #000;
            height: 35px;
            line-height: 35px;
            padding: 0 5px;
        }

        .icon_list span:hover,.el-dropdown:hover{
            background-color: #FEE759;
        }
    }
}

.el-dropdown-menu__item:focus, .el-dropdown-menu__item:not(.is-disabled):hover{
    background-color: #f7ab00;
    color: #000;
}
</style>
